import 'dart:async';
import 'dart:ui' as ui;
import 'package:image_picker/image_picker.dart';
import 'package:permission_handler/permission_handler.dart';


class ImageUtil {

  /// 从相册选择图片
  static Future<String> selectImage({bool? maxSize}) async {
    // bool isPer = await PermissionUtil.reqPer(AppData.instance.isIOS() ? Permission.photos : Permission.storage);
    // if(!isPer){
    //   ToastUtil.toast('没有权限');
    //   return '';
    // }
    final ImagePicker _picker = ImagePicker();
    // Pick an image
    final XFile? image = await _picker.pickImage(source: ImageSource.gallery);
    /*// Capture a photo
    final XFile? photo = await _picker.pickImage(source: ImageSource.camera);
    // Pick a video
    final XFile? image = await _picker.pickVideo(source: ImageSource.gallery);
    // Capture a video
    final XFile? video = await _picker.pickVideo(source: ImageSource.camera);
    // Pick multiple images
    final List<XFile>? images = await _picker.pickMultiImage();*/

    if(maxSize ?? true) {
      int length = await image?.length() ?? 0;
      if(length > 10 * 1024 * 1024){
        // ToastUtil.toast('图片大小要求小于10M');
        return '';
      }
    }

    return image?.path ?? '';
  }
}